/**
 * 新增材料商品
 * 胡琼
 * 2017/8/21
 **/
var testConfig = require('../testConfig');
const ipcRenderer = require('electron').ipcRenderer;
var l = parseInt(window.sessionStorage.getItem("runTimes"));
var planData = JSON.parse(window.sessionStorage.getItem('planData'));
var caseData =  planData.cases[l];
var msg = {
    reportId:planData.reportId,
    taskId:planData.taskId,
    caseId:caseData.caseId,
    caseNumber:caseData.caseNumber,
    isOver:'false'
};
function TestProject() {
    this.init = function () {
        var arr = [];
        arr.push(this.step1,
            this.step2,
            this.step3,
            this.step4,
            this.step5,
            this.step6,
            this.step7,
            this.step8,
            this.step9,
            this.step10,
            this.step11,
            this.step12);
        testConfig.testFun.runStep(arr);
    };
    this.step1 = function () {
        $("div.index-aside-nav-menu").find(".index-first-nav li:nth-child(1)")[0].click();
        msg.stepResult = {
            byname:"skipGoodsManage",
            realData:$("#id-main-frame iframe").attr('src')
        };
        ipcRenderer.sendToHost(JSON.stringify(msg));
    };
    this.step2 = function () {
        testConfig.testFun.as().find(".cmn-addgoods-btn")[0].click();
        msg.stepResult = {
            byname:"skipAddGoods",
            realData:testConfig.testFun.bs().find("#layui-layer-iframe1").attr('src')
        };
        ipcRenderer.sendToHost(JSON.stringify(msg));
    };
    this.step3 = function () {
        testConfig.testFun.bs().find("input[data-name='name']").val('自动化测试商品2');
        msg.stepResult = {
            byname:"name",
            realData:testConfig.testFun.bs().find("input[data-name='name']").val()
        };
        ipcRenderer.sendToHost(JSON.stringify(msg));
    };
    this.step4 = function () {
        testConfig.testFun.bs().find("#id-select-type_0").attr({'index':'0'}).html('<option json-data="{id:1764,name:自动化测试材料分类2,level:2,categoryType:1,status:1,isleaf:0,unit:null}" value="1764">自动化测试材料分类2</option>');
        msg.stepResult = {
            byname:"goodsClassify",
            realData:testConfig.testFun.bs().find("#id-select-type_0").val()
        };
        ipcRenderer.sendToHost(JSON.stringify(msg));
    };
    this.step5 = function () {
        testConfig.testFun.bs().find("#id-select-category").html('<option data-unit="吨" data-value="1767">自动化品种2</option>');
        msg.stepResult = {
            byname:"breed",
            realData:testConfig.testFun.bs().find("#id-select-category").val()
        };
        ipcRenderer.sendToHost(JSON.stringify(msg));
    };
    this.step6 = function () {
        testConfig.testFun.bs().find(".per-defined-unit")[0].click();
        msg.stepResult = {
            byname:"unit",
            realData:testConfig.testFun.bs().find(".per-defined-unit").val()
        };
        ipcRenderer.sendToHost(JSON.stringify(msg));
    };
    this.step7 = function () {
        testConfig.testFun.bs().find("#id-add-attribute-btn")[0].click();
        msg.stepResult = {
            byname:"inputShow",
            realData:testConfig.testFun.bs().find("#id-add-attribute-btn")
        };
        ipcRenderer.sendToHost(JSON.stringify(msg));
    };
    this.step8 = function () {
        testConfig.testFun.bs().find(".attributeInput").val('吨');
        msg.stepResult = {
            byname:"attributeInput",
            realData:testConfig.testFun.bs().find(".attributeInput").val()
        };
        ipcRenderer.sendToHost(JSON.stringify(msg));
    };
    this.step9 = function () {
        testConfig.testFun.bs().find(".buyInput").val('100');
        msg.stepResult = {
            byname:"buyInput",
            realData:testConfig.testFun.bs().find(".buyInput").val()
        };
        ipcRenderer.sendToHost(JSON.stringify(msg));
    };
    this.step10 = function () {
        testConfig.testFun.bs().find("#img_1").attr('src', 'http://choosefine-uat.oss-cn-hangzhou.aliyuncs.com/shopping/user/20170814090454RYyWBaRd3i.jpg');
        msg.stepResult = {
            byname:"goodsImg",
            realData:testConfig.testFun.bs().find("#img_1").attr('src')
        };
        ipcRenderer.sendToHost(JSON.stringify(msg));
    };
    this.step11 = function () {
        testConfig.testFun.bs().find(".btn-submit")[0].click();
        msg.stepResult = {
            byname:"goGoodsManage",
            realData:testConfig.testFun.as().find("#id-main-frame").attr('src')
        };
        ipcRenderer.sendToHost(JSON.stringify(msg));
    };
    this.step12 = function(){
        var address = window.location.href;
        var r = parseInt(window.sessionStorage.getItem("runTimes"));
        if(planData.cases[r+1].caseNumber){
            if (address.indexOf("?") > 0) {
                window.location.href = address + "&_from=" + planData.cases[r+1].caseNumber;
            } else {
                window.location.href = address + "?_from=" + planData.cases[r+1].caseNumber;
            }
        }
        window.sessionStorage.setItem("runTimes",r+1);
    }
}
function testStart() {
    var test = new TestProject();
    test.init();
}
exports.start = testStart;


